package no.ntnu.fp.messages.impl;

import org.w3c.dom.Document;
import org.w3c.dom.Element;

import no.ntnu.fp.messages.Message;
import no.ntnu.fp.messages.MessageCode;
import no.ntnu.fp.model.Meeting;
import no.ntnu.fp.model.Notice;
import no.ntnu.fp.utils.XmlParser;

public class AcceptNoticeMessage implements Message {
	private final Notice notice;
	
	public AcceptNoticeMessage(Notice notice) {
		this.notice = notice;
	}

	public AcceptNoticeMessage() {
		this(null);
	}

	public Notice getNotice() {
		return notice;
	}

	@Override
	public MessageCode getMessageCode() {
		return MessageCode.ACCEPT_NOTICE_MESSAGE;
	}
	
	@Override
	public Message fromXmlString(String xml) {
		Document document = XmlParser.parseXmlString(xml);
		Notice notice = new Notice((Element)document.getElementsByTagName("notice").item(0));
		return new AcceptNoticeMessage(notice);
	}

	@Override
	public String toString() {
		Document document = XmlParser.getThreadLocalDocumentBuilder().newDocument();
		Element messageElement = document.createElement("message");
		messageElement.appendChild(notice.toXml(document));
		return getMessageCode() + XmlParser.convertXmlToString(messageElement);
	}

}
